@import 'mixins/size';

@keyframes form-pending-top {
  0% {
    left: -100%;
  }

  50%,
  100% {
    left: 100%;
  }
}
@keyframes form-pending-right {
  0% {
    top: -100%;
  }

  50%,
  100% {
    top: 100%;
  }
}
@keyframes form-pending-bottom {
  0% {
    right: -100%;
  }

  50%,
  100% {
    right: 100%;
  }
}
@keyframes form-pending-left {
  0% {
    bottom: -100%;
  }

  50%,
  100% {
    bottom: 100%;
  }
}

@include b(form) {
  display: flex;
  flex-flow: row wrap;

  @include component-size;

  @include e(item) {
    position: relative;

    @include m(vertical) {
      @include e(item-container) {
        flex-direction: column;
      }

      @include e(item-label) {
        justify-content: flex-start;
      }
    }
  }

  @include e(item-container) {
    display: flex;
    align-items: flex-start;
    width: 100%;
  }

  @include e(item-label) {
    @include utils-ellipsis;

    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;
    min-height: var(--#{$rd-prefix}size);
    padding-right: 8px;

    @include m(required) {
      &::before {
        display: inline-block;
        margin-right: 4px;
        color: var(--#{$rd-prefix}color-danger);
        content: '*';
      }
    }

    @include m(colon) {
      &::after {
        margin-left: 2px;
        content: ':';
      }
    }
  }

  @include e(item-label-extra) {
    @include polyfill-column-gap(4px);

    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    font-size: 0.9em;
    line-height: 1;
    color: var(--#{$rd-prefix}text-color-sub);
  }

  @include e(item-content) {
    position: relative;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    min-height: var(--#{$rd-prefix}size);
  }

  @include e(pending) {
    position: absolute;
    z-index: 5;
    display: block;
    overflow: hidden;

    &::before {
      position: absolute;
      z-index: 1;
      display: block;
      width: 100%;
      height: 100%;
      content: '';
      background-color: var(--#{$rd-prefix}color-border);
    }

    &::after {
      position: absolute;
      z-index: 2;
      display: block;
      width: 100%;
      height: 100%;
      content: '';
    }

    @include m(1) {
      top: 0;
      left: 0;
      width: 100%;
      height: 1px;

      &::after {
        left: 0;
        background: linear-gradient(90deg, transparent, var(--#{$rd-prefix}color-primary));
        animation: form-pending-top 1s linear infinite;
        animation-fill-mode: backwards;
      }
    }

    @include m(2) {
      top: 0;
      right: 0;
      width: 1px;
      height: 100%;

      &::after {
        top: -100%;
        background: linear-gradient(180deg, transparent, var(--#{$rd-prefix}color-primary));
        animation: form-pending-right 1s linear infinite;
        animation-delay: 0.25s;
        animation-fill-mode: backwards;
      }
    }

    @include m(3) {
      bottom: 0;
      left: 0;
      width: 100%;
      height: 1px;

      &::after {
        right: 0;
        background: linear-gradient(270deg, transparent, var(--#{$rd-prefix}color-primary));
        animation: form-pending-bottom 1s linear 0.5s infinite;
        animation-fill-mode: backwards;
      }
    }

    @include m(4) {
      top: 0;
      left: 0;
      width: 1px;
      height: 100%;

      &::after {
        bottom: -100%;
        background: linear-gradient(360deg, transparent, var(--#{$rd-prefix}color-primary));
        animation: form-pending-left 1s linear infinite;
        animation-delay: 0.75s;
        animation-fill-mode: backwards;
      }
    }
  }

  @include e(feedback-icon) {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2em;
    height: var(--#{$rd-prefix}size);
    font-size: 1.1em;

    @include when(pending) {
      color: var(--#{$rd-prefix}color-primary);
    }
    @include when(error) {
      color: var(--#{$rd-prefix}color-danger);
    }
    @include when(warning) {
      color: var(--#{$rd-prefix}color-warning);
    }
    @include when(success) {
      color: var(--#{$rd-prefix}color-success);
    }
  }

  @include e(error-container) {
    float: right;
    min-height: calc(1.5em + 5px);
    padding: 2px 0;
  }

  @include e(error) {
    @include utils-ellipsis;

    font-size: 0.9em;

    @include m(error) {
      color: var(--#{$rd-prefix}color-danger);
    }

    @include m(warning) {
      color: var(--#{$rd-prefix}color-warning);
    }
  }
}
